from IDCard import IdCard

def main():
    print('\n=== 身份证号码信息查看器 ===\n')
    
    while True:
        try:
            id_number = input('请输入身份证号码(按q退出):').strip()
            if id_number.lower() == 'q':
                break
                
            idcard = IdCard(id_number)
            info = idcard.info_to_dict
            
            print('\n身份证信息:')
            print(f'行政区划: {info["fullarea"]}')
            print(f'出生日期: {info["birthday"].strftime("%Y年%m月%d日")}')
            print(f'性    别: {info["sex_cn"]}')
            print(f'年    龄: {info["age"]}岁')
            
        except ValueError as e:
            print(f'\n错误: {str(e)}')
        except Exception as e:
            print(f'\n发生未知错误: {str(e)}')
        finally:
            print('\n' + '-' * 50 + '\n')

if __name__ == '__main__':
    main()